/*************************************************************************
	> File Name: monolith/core/memory_utils.h
	> Author: dzhang
	> Mail: dong.zhang@ingenic.com 
	> Created Time: Thu 17 Dec 2020 11:14:47 AM CST
 ************************************************************************/

#ifndef _MONOLITH_CORE_MEMORY_UTILS_H_
#define _MONOLITH_CORE_MEMORY_UTILS_H_
#include <iostream>
#include "monolith/core/macros.h"
CC_NAME_SPACE_BEGIN

#ifdef __cplusplus
extern "C" {
#endif

#define ML_MEMORY_ALIGN_DEFAULT 64

/**
 * @brief alloc memory with given size & alignment.
 * @param size  given size. size should > 0.
 * @param align given alignment.
 * @return memory pointer.
 * @warning use `MNNMemoryFreeAlign` to free returned pointer.
 * @sa MNNMemoryFreeAlign
 */
ML_PUBLIC void* memory_alloc_align(size_t size, size_t align);

/**
 * @brief alloc memory with given size & alignment, and fill memory space with 0.
 * @param size  given size. size should > 0.
 * @param align given alignment.
 * @return memory pointer.
 * @warning use `MNNMemoryFreeAlign` to free returned pointer.
 * @sa MNNMemoryFreeAlign
 */
ML_PUBLIC void* memory_calloc_align(size_t size, size_t align);

/**
 * @brief free aligned memory pointer.
 * @param mem   aligned memory pointer.
 * @warning do NOT pass any pointer NOT returned by `MNNMemoryAllocAlign` or `MNNMemoryCallocAlign`.
 * @sa MNNMemoryAllocAlign
 * @sa MNNMemoryCallocAlign
 */
ML_PUBLIC void memory_free_align(void* mem);

#ifdef __cplusplus
}
#endif
CC_NAME_SPACE_END
#endif //_MONOLITH_CORE_MEMORY_UTILS_H
